package cn.com.huzo.repository.purchase.impl;

import cn.com.huzo.model.entities.purchase.NonMaterialCostHeaderEntity;
import huzofw.repository.impl.GenericRepositoryImpl;
import huzofw.repository.impl.MyBatisDaoUtils;
import cn.com.huzo.repository.purchase.NonMaterialCostHeaderRepository;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Repository;

/**
 * 非材料花费信息数据访问对象。
 *
 * @author 范学春
 */
@Repository("NonMaterialCostHeaderRepository")
public class NonMaterialCostHeaderRepositoryImpl extends GenericRepositoryImpl<NonMaterialCostHeaderEntity, Long>
        implements NonMaterialCostHeaderRepository {

    private final String namespace = "cn.com.huzo.repository.purchase.NonMaterialCostHeaderRepository";

    /**
     * 构造函数,设置the instance to ProductRepositoryImpl.class.
     */
    public NonMaterialCostHeaderRepositoryImpl() {
        super(NonMaterialCostHeaderEntity.class);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public NonMaterialCostHeaderEntity fetchByKey(Long key) {
        return getSqlSession().selectOne(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchByKey"), key);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer fetchForCount(Map<String, Object> filters) {
        return getSqlSession().selectOne(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchForCount"), filters);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<NonMaterialCostHeaderEntity> fetchForPage(Map<String, Object> filters) {
        return getSqlSession().selectList(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchForPage"), filters);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Long insert(NonMaterialCostHeaderEntity instance) {
        // 影响的行数
        int rowsAffected = getSqlSession().insert(MyBatisDaoUtils.getMapperQueryId(
                namespace, "insert"), instance);

        // 返回出入后的记录ID
        return instance.getHeaderId();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer update(NonMaterialCostHeaderEntity instance) {
        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "update"), instance);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer delete(Long key) {
        return getSqlSession().delete(MyBatisDaoUtils.getMapperQueryId(
                namespace, "delete"), key);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer doCheck(NonMaterialCostHeaderEntity instance) {
        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "check"), instance);
    }
}
